package com.hainabo.mgcmall.api.datafetcher;

import com.hainabo.mgcmall.dao.Product;
import com.hainabo.mgcmall.dao.ProductRepository;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by surfingren on 2017/9/3.
 */
@Component
public class ProductAllDataFetcher implements DataFetcher<List<Product>>{

    @Autowired
    ProductRepository productRepository;

    @Override
    public List<Product> get(DataFetchingEnvironment environment) {

        Iterable<Product> all = productRepository.findAll();
        return (List<Product>) all;
    }
}
